<template>
    <zh-form ref="formRef" :span="24" :model="state.formData" :rules="state.rules" label-width="120px">
		<zh-form-cascader
			prop="orgType"
			label="组织类型"
			placeholder="请选择"
			:show-all-levels="false"
			:props="{ label: 'title', leaf: 'isLeaf', treeList: 'treeList', emitPath: false, checkStrictly: true }"
			v-model="state.formData.orgType"
			:options="state.orgTypeSelectTreeData"
			:disabled="true"
		></zh-form-cascader>
        <zh-form-input  prop="orgName" label="单位名称" placeholder="必填,请按营业执照上的名称进行填写" v-model="state.formData.orgName"></zh-form-input>
		<zh-form-input
			prop="creditCode"
			label="社会信用码"
			placeholder="可为空，建议填写"
			v-model="state.formData.creditCode"
		></zh-form-input>
        <zh-form-input prop="contact" label="单位联系人"  placeholder="可为空" v-model="state.formData.contact"></zh-form-input>
		<zh-form-input prop="cellphone" label="单位联系人手机"  placeholder="可为空" v-model="state.formData.cellphone"></zh-form-input>
		<zh-form-input prop="phone" label="单位联系电话"  placeholder="可为空" v-model="state.formData.phone"></zh-form-input>
        <zh-form-input prop="orgNo" label="组织机构代码"  placeholder="可为空" v-model="state.formData.orgNo"></zh-form-input>
        <zh-form-input prop="address" label="地址" placeholder="可为空" v-model="state.formData.address" ></zh-form-input>
		<zh-form-input
			prop="remarks"
			:span="24"
			type="textarea"
			label="备注"
			placeholder=""
			v-model="state.formData.remarks"
		></zh-form-input>
		<zh-form-upload
			prop="logShowId"
			label="营业执照照片"
			:limit="1"
			:span="24"
			fileTypes="png,jpg,jpeg,svg,gif"
			fileNamePrefix="衣服图片"
			limitDesc="上传文件类型仅限png,jpg,jpeg,svg,gif"
			v-model="state.formData.logShowId"
		></zh-form-upload>
	</zh-form>
</template>
<script lang="ts" setup>
import { reactive } from 'vue';
import { ElMessage } from 'element-plus';
let formRef=ref()
const props = defineProps({
	modelValue: [Boolean],
    loading: [Boolean],
    areaCode: {
		type: String,
		default() {
			return '';
		},
	},
    orgType: {
		type: String,
		default() {
			return '';
		},
	},
});
const emit = defineEmits(['update:modelValue','update:loading']);
const state=reactive({
    formData:{areaCode:props.areaCode,orgType:props.orgType} as any,
    orgTypeSelectTreeData:[],
    loading:false,
    rules:{
        orgName: [
            {
                required: true,
                message: '请输入单位名称',
                trigger: 'blur',
            },
        ],
        orgType: [
            {
                required: true,
                message: '请选择组织类型',
                trigger: 'blur',
            },
        ],
    }
})
const save=async ()=>{
    let checkFlag = await formRef.value.checkForm();
	if (checkFlag) {
		//校验通过	
        emit('update:loading', true);	
		$api.common.send.post('org0025', state.formData).then(() => {
            ElMessage.success('新增成功！');
            emit('update:modelValue', false);
            emit('update:loading', false);	
        }).catch((err) => {
            emit('update:loading', false);	
        });
			
	}
}
onMounted(() => {
    const paramsTree = {
        dictField: 'orgType',
    };
    $api.common.send.post('dict0025', paramsTree).then((res) => {
        state.orgTypeSelectTreeData = res.result;
    });
})

defineExpose({ form: state.formData, save });
</script>